package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.Map;

public interface UserMapper {
    /**
     * 通过openid获取用户信息
     * @param openid
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User getByOpenid(String openid);

    @Insert("insert into user values(null,#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})")
    @Options(useGeneratedKeys = true , keyProperty = "id")
    void insert(User user);

    /**
     * 通过用户id获取用户信息
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    /**
     * 统计用户数
     * @param beginTime
     * @param endTime
     * @return
     */
    Integer countByTime(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 统计用户数
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
